package com.hbuzzs.shiro.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hbuzzs.shiro.entity.MyPermission;
import com.hbuzzs.shiro.entity.RolePermission;
import com.hbuzzs.shiro.mapper.PermissionMapper;
import com.hbuzzs.shiro.mapper.RoleMapper;
import com.hbuzzs.shiro.mapper.RolePermissionMapper;
import com.hbuzzs.shiro.mapper.UserRoleMapper;
import com.hbuzzs.shiro.service.IRolePermissionService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author zhangzhishun
 * @since 2020-10-11
 */
@Service
@RequiredArgsConstructor
public class RolePermissionServiceImpl extends ServiceImpl<RolePermissionMapper, RolePermission> implements IRolePermissionService {

    private final RolePermissionMapper rolePermissionMapper;
    private final PermissionMapper permissionMapper;
    private final UserRoleMapper userRoleMapper;
    private final RoleMapper roleMapper;

    @Override
    public List<MyPermission> getPermissionByRoleId(String roleId) {
        return rolePermissionMapper.getPermissionByRoleId(roleId);
    }

    @Override
    public List<MyPermission> getPermissionByUserIdRoleName(String userId, String roleName) {
        // 获取用户的角色ID
        String roleId = userRoleMapper.getRoleIdByUserIdRoleName(userId, roleName);
        // 根据角色ID获取所有权限集合
        return getPermissionByRoleId(roleId);
    }

}
